package org.rcgwt.client.ui.validator.events;

import org.rcgwt.client.ui.validator.messages.Message;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.user.client.ui.Widget;

/**
 * A MessageEvent object which permits the communication between a widget and a
 * MessageDisplay component.
 * 
 * @author Elian ORIOU
 * 
 */

public class MessageEvent extends GwtEvent<MessageHandler> {

	private Message message;
	private Widget sender;

	private static final GwtEvent.Type<MessageHandler> TYPE = new GwtEvent.Type<MessageHandler>();

	public MessageEvent(Message e, Widget s) {
		this.message = e;
		this.sender = s;
	}

	@Override
	protected void dispatch(MessageHandler handler) {
		handler.onMessageEvent(this);
	}

	@Override
	public com.google.gwt.event.shared.GwtEvent.Type<MessageHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<MessageHandler> getType() {
		return TYPE;
	}

	public Message getMessage() {
		return message;
	}

	public void setSender(Widget sender) {
		this.sender = sender;
	}

	public Widget getSender() {
		return sender;
	}

	@Override
	public String toString() {
		return "MessageEvent [message=" + message + ", sender=" + sender + "]";
	}
}
